﻿/* 
	PureMVC CSharp / WPF / EmployeeAdmin Demo - Login
	By Andy Adamczak <andy.adamczak@puremvc.org>
	Copyright(c) 2009 Andy Adamczak, Some rights reserved.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using PureMVC.Patterns;
using PureMVC.Interfaces;
using System.Windows.Forms;
using System.Drawing;


using GEF2.Model.Storage;
using GEF2.Model;
using GEF2;

namespace GEF2.Controller
{
	public class AddEntityCommand : SimpleCommand, ICommand
	{
		public override void Execute(INotification notification)
		{
            Point location = (Point) notification.Body;
            EntityProxy entityProxy = (EntityProxy)Facade.RetrieveProxy(EntityProxy.NAME);
            SearchProxy searchProxy = (SearchProxy)Facade.RetrieveProxy(SearchProxy.NAME);
            InputName nameDlg = new InputName();
            if (nameDlg.ShowDialog() == DialogResult.OK)
            {
                if (searchProxy.isNameUnique(nameDlg.getText()))
                {
                    Entity entity = entityProxy.NewEntity(nameDlg.getText(), location);
                    SendNotification(ApplicationFacade.ENTITY_ADDED, entity);
                }
            }

		}
	}
}
